import axios from "axios";

const getProjectByUserId = async (status: number | null) => {
    const userId = sessionStorage.getItem("user.id");
    const position = sessionStorage.getItem("user.position");

    let url = "/api/project";

    if (position == "publisher") {
        return new Promise((resolve, reject) => {
            url += "/selectProjectByPublisherId";
            axios.get(url, {
                params: {
                    publisherId: userId,
                    status
                }
            }).then(function (response) {
                resolve(response.data);
            });
        })


    } else if (position == "admin") {

        if (status == null) {
            return new Promise(((resolve, reject) => {
                url += "/selectUnDoneProject";
                axios.get(url).then(function (response) {
                    resolve(response.data);
                })
            }))
        } else {
            return new Promise(((resolve, reject) => {
                url += "/selectProjectByAdminId";
                axios.get(url, {
                    params: {
                        adminId: userId, status
                    }
                }).then(function (response) {
                    resolve(response.data);
                })
            }))
        }
    }
}

export default getProjectByUserId;



